var app = getApp();
Page( Object.assign({},{
    data:{
        info : {},
        show : false,
        datalist : [],
        page : {
            isend : false,
            doing : false,
            doo : 'quest',
            pdata : {
                op : 'replylist',
                page : 1,
                qid : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        content : '',
        goodsinfo : false,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        var id = options.id ? options.id : '';
        var zfid = options.zfid ? options.zfid : 0;

        self.setData({
            options : options,
            'page.pdata.qid' : id,
        })

        app.com.http('quest','POST',{op:'info',id:id,zfid:zfid},0,false,'','',function(res){
            if (!res.data.errno && res.data) {
                self.setData({
                    info : res.data.data.info,
                    params : res.data.data.params,
                    sharedata : res.data.data.sharedata,
                    goodsinfo : res.data.data.goodsinfo ? res.data.data.goodsinfo : false,
                    inited : true,
                });

                wx.setNavigationBarTitle({
                    title: res.data.data.info.title
                });

            }else{
                app.com.alert(res.data.message,function(){
                    app.com.backPage(0);
                });
            }
        });
        self.onReachBottom();
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
        wx.stopPullDownRefresh();
    },
    contentfn(e){
        this.setData({
            content : e.detail.value
        })
    },
    sub(){
        var self = this;
        var postdata = {
            op : 'reply',
            qid : self.data.info.id,
            content : self.data.content,
        };
        app.com.http('quest','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno && res.data) {
                app.com.alert(res.data.message,function(){
                    self.setData({
                        datalist : [],
                        'page.pdata.page' : 1,
                        'page.isend' : false,
                        'page.nodataf' : 0,
                        'page.doing' : false,
                        show : false,
                        content : '',
                    })
                    self.onReachBottom();
                });
            }else{
                app.com.toast(res.data.message);
            }
        });
    },
    zanit(e){
        var self = this;
        var postdata = {
            op : 'zan',
            rid : e.currentTarget.dataset.id,
        };
        var index = e.currentTarget.dataset.i;
        app.com.http('quest','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno && res.data) {
                self.setData({
                    ['datalist['+index+'].zan'] : self.data.datalist[index]['zan']*1 + 1
                })
                app.com.toast(res.data.message);
            }else{
                app.com.toast(res.data.message);
            }
        });
    },
    answer(){
        if( this.data.info.isneedauth ){
            this.setData({
                showuserbtn : true,
            })
            return false;
        }
        this.setData({
            show : true
        })
    },
    onClose(){
        this.setData({
            show : false
        })
    },
    updateUserInfo : function(e){
        var self = this;
        
        app.com.getUserInfo(function(res){
            self.setData({
                showuserbtn : false,
                'info.isneedauth' : false,
            });
            self.answer();
        },false,e.detail);
    },
    hideauth(){
        this.setData({
            showuserbtn:false,
        });
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e);
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    weburl : function(e){
        app.com.toweburl( e,this );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },
    FormIdsubmit : function(e){
        if( app.globalData.formarr.length <= 20 ) app.globalData.formarr.push(e.detail.formId);
    },
    
}))